package com.stox.converter;

import java.util.Collection;

import lombok.Delegate;

import org.dozer.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BeanMapper {
	private static final Logger logger = LoggerFactory.getLogger(BeanMapper.class);

	@Delegate
	private Mapper mapper;
	
	public <T extends Collection<V>, V> T map(Collection<?> sourceCollection, Class<T> destinationCollectionType,  Class<V> destinationType){
		T destinationCollection = null;
		try {
			destinationCollection = destinationCollectionType.newInstance();
			for(Object source : sourceCollection)
				destinationCollection.add(map(source, destinationType));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new RuntimeException(e);
		}
		return destinationCollection;
	}

	public void setMapper(Mapper mapper) {
		this.mapper = mapper;
	}
	
}
